<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>安全设置</title>
<link rel="stylesheet" href="/js/layui-2.5.4/css/layui.css">
<script src="/js/layui-2.5.4/layui.js"></script>
</head>
<body>
	<blockquote class="layui-elem-quote">安全设置</blockquote>
	<form id="update-pwd-form" class="layui-form layui-form-pane"
		lay-filter="update-pwd-form">
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-block">
				<input id="password1" type="password" name="password1"
					class="layui-input" placeholder="请输入新密码" maxlength="20"
					lay-verify="required">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-block">
				<input id="password2" type="password" name="password2"
					class="layui-input" placeholder="请输入确认密码" maxlength="20"
					lay-verify="required">
			</div>
		</div>
		<div class="layui-form-item" style="text-align: center;">
			<button class="layui-btn" lay-submit
				lay-filter="update-pwd-form-submit">保存</button>
			<button class="layui-btn layui-btn-primary" type="reset">清空</button>
		</div>
	</form>

	<script>
		//JavaScript代码区域
		layui.use([ 'jquery', 'layer', 'element', 'form' ], function() {
			var $ = layui.$;
			var layer = layui.layer;
			var element = layui.element;
			var form = layui.form;
			$('#update-pwd-form')[0].reset();
			// 用户信息表单提交
			form.on('submit(update-pwd-form-submit)', function(data) {
				// ajax方式更新用户
				/* var data = {
					pwd1 : $('#password1').val(),
					pwd2 : $('#password2').val()
				} */
				//data.field.pwda=$('#password1').val();
				//data.field.pwdb=$('#password2').val();
				console.log(data.field);
				$.ajax({
					url : "/student/uppwd",
					type : "PUT",
					data : JSON.stringify(data.field),
					contentType : 'application/json',
					dataType : 'json',
					success : function(data) {
						//console.log(data)
						if (data.status == 1) {
							layer.open({
								title : '安全设置成功，请使用新密码登陆！',
								content : data.msg,
								shade : 0.3,
								time : 3000,
								end : function() {
									window.parent.location.href = "/login";
								}
							});
						} else {
							parent.layer.msg(data.msg, {
								icon : 2,
								shade : 0.3,
								time : 2000
							});
						}
					},
					error : function() {
						layer.open({
							title : '系统提示',
							content : '发生未知错误，请联系管理员！'
						});
					}
				});
				// 阻止表单跳转
				return false;
			});

		});
	</script>
</body>
</html>